package com.graduation.lastproject.service.business.businessHighActive.impl;

import com.graduation.lastproject.dao.business.BusinessHighDao;
import com.graduation.lastproject.entity.Bookorder;
import com.graduation.lastproject.entity.BusinessIncom;
import com.graduation.lastproject.entity.Review;
import com.graduation.lastproject.service.business.businessHighActive.BusinessHighService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.misc.Request;

import java.util.*;

@Service
public class IBusinessHighService implements BusinessHighService {
    @Autowired
    private BusinessHighDao businessHighDao;
    @Override
    public int uploadFileEdit(Map<String, Object> hotelInfo) {
        return businessHighDao.uploadFileEdit(hotelInfo);
    }

    @Override
    public int deleteHotelPicInfo(String hotelId) {
        return businessHighDao.deleteHotelPicInfo(hotelId);
    }

    @Override
    public int updataPicInfo(Map<String, Object> info) {
        return  businessHighDao.updataPicInfo(info);
    }

    @Override
    public int getOrderTotal(Bookorder bookorder) {
        return businessHighDao.getBOrderTotal(bookorder);
    }

    @Override
    public List<Bookorder> getOrderInfoListPage(Bookorder bookorder) {
        return businessHighDao.getBOrderInfoListPage(bookorder);
    }

    @Override
    public int getBReviewTotal(Review review) {
        return businessHighDao.getBReviewTotal(review);
    }

    @Override
    public List<Review> getBReviewInfoListPage(Review review) {
        return businessHighDao.getBReviewInfoListPage(review);
    }

    @Override
    public int businessReturnReview(Map<String, Object> map) {
        return businessHighDao.businessReturnReview(map);
    }

    @Override
    public List<BusinessIncom> getTotalInPrice(String bphone, String year) {
        /*处理 如果某一个月没有收入  添加月份以及收入为0*/
        List<BusinessIncom> list=businessHighDao.getTotalInPrice(bphone,year);
        Integer[] minMonth=new Integer[12];
        for(int i = 0;i<list.size();i++){
           minMonth[i]=list.get(i).getTotal_month();
        }
        Integer[] month={1,2,3,4,5,6,7,8,9,10,11,12};
        List<BusinessIncom> lists = compare(minMonth,month);
        list.addAll(lists);
     //根据total_month进行排序
        Collections.sort(list, new Comparator<BusinessIncom>() {
            @Override
            public int compare(BusinessIncom o1, BusinessIncom o2) {
                int i = o1.getTotal_month() - o2.getTotal_month();
                return i;
            }
        });
        return list;
    }

    public static List<BusinessIncom> compare(Integer[] num1, Integer[] num2) {
        List<Integer> listFirst = Arrays.asList(num1);
        List<BusinessIncom> listSecond = new ArrayList<BusinessIncom>();
        for (Integer t : num2) {
            if (!listFirst.contains(t)) {
                BusinessIncom businessIncom=new BusinessIncom();
                businessIncom.setTotal_month(t);
                businessIncom.setTotal_price(0);
                listSecond.add(businessIncom);
            }
        }
        return listSecond;
    }
}
